﻿package mortal.game.view.rebate.openNewSerSevenDay.active2
{
    import Message.Public.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.copy.QuestionCopy.data.*;
    import mortal.game.view.rebate.data.*;
    import mortal.game.view.rebate.item.*;
    import mortal.mvc.core.*;

    public class OpenNewSerSevBottom2 extends GSprite
    {
        protected var _leftBg:GImageBitmap;
        protected var _rbg:GImageBitmap;
        protected var _fbg:GImageBitmap;
        protected var _level7:GImageBitmap;
        protected var _firstTitle:GImageBitmap;
        protected var _tip4:GTextFiled;
        protected var _line1:ScaleBitmap;
        protected var _items1:CellsGridSprite;
        protected var _items2:CellsGridSprite;
        protected var _line2:ScaleBitmap;
        protected var _items3:CellsGridSprite;
        protected var _items4:CellsGridSprite;
        protected var _line3:ScaleBitmap;
        protected var _btn1:GLoadingButton;
        protected var _btn2:GLoadingButton;
        protected var _btn3:GLoadingButton;
        protected var _btn4:GLoadingButton;
        protected var _levelT6:GImageBitmap;
        protected var _levelT5:GImageBitmap;
        protected var _levelT4:GImageBitmap;
        protected var _level7Tip:GImageBitmap;
        protected var _level6:GImageBitmap;
        protected var _level5:GImageBitmap;
        protected var _level4:GImageBitmap;
        private var _btnArr:Array;
        private var _numArr:Array;
        private var _infoArr:Array;
        private var targetTypeNameStrObj:Object;

        public function OpenNewSerSevBottom2()
        {
            this._btnArr = [];
            this._numArr = [7, 6, 5, 4];
            this.targetTypeNameStrObj = {10:8, 11:9, 12:10, 13:11};
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._leftBg = UIFactory.gImageBitmap(ImagesConst.OpenServerSevenDayBgNumOne, 0, 0, this);
            this._rbg = UIFactory.gImageBitmap(ImagesConst.OpenServerSevenDayBgNumOne, 339, 0, this);
            this._fbg = UIFactory.gImageBitmap(ImagesConst.OpenNewSerSevZfirstBg, -3, 15, this);
            this._level7 = UIFactory.gImageBitmap(ImagesConst.openNewSerSevDayAct2Title_8_7, 125, 13, this);
            this._firstTitle = UIFactory.gImageBitmap(ImagesConst.openNewSerSevDayAct2Order7, 160, 13, this);
            this._tip4 = UIFactory.gTextField("" + Language.getString(71791), 95, 222, 200, 20, this, GlobalStyle.textFormatLv.setSize(13).setBold(true));
            this._line1 = UIFactory.bg(2, 216, 322, 2, this, ImagesConst.SplitLine4);
            this._items1 = UIFactory.getUICompoment(CellsGridSprite);
            this._items1.colNum = 2;
            this._items1.vCellWid = 72;
            this._items1.hCellWid = 72;
            this._items1.genCellFun = this.genItem;
            this._items1.genCells(4);
            this._items1.x = 28;
            this._items1.y = 60;
            this.addChild(this._items1);
            this._items2 = UIFactory.getUICompoment(CellsGridSprite);
            this._items2.colNum = 3;
            this._items2.vCellWid = 73;
            this._items2.hCellWid = 3;
            this._items2.genCellFun = this.genItem;
            this._items2.genCells(3);
            this._items2.x = 430;
            this._items2.y = 6;
            this.addChild(this._items2);
            this._line2 = UIFactory.bg(342, 82, 321, 2, this, ImagesConst.SplitLine4);
            this._items3 = UIFactory.getUICompoment(CellsGridSprite);
            this._items3.colNum = 3;
            this._items3.vCellWid = 73;
            this._items3.hCellWid = 73;
            this._items3.genCellFun = this.genItem;
            this._items3.genCells(3);
            this._items3.x = 430;
            this._items3.y = 89;
            this.addChild(this._items3);
            this._items4 = UIFactory.getUICompoment(CellsGridSprite);
            this._items4.colNum = 3;
            this._items4.vCellWid = 73;
            this._items4.hCellWid = 73;
            this._items4.genCellFun = this.genItem;
            this._items4.genCells(3);
            this._items4.x = 431;
            this._items4.y = 172;
            this.addChild(this._items4);
            this._line3 = UIFactory.bg(340, 164, 321, 2, this, ImagesConst.SplitLine4);
            this._btn1 = UIFactory.gLoadingButton(ImagesConst.LineOffCopyCellBtn_upSkin, 213, 161, 70, 27, this);
            this._btn1.label = "" + Language.getString(71792);
            this._btn2 = UIFactory.gLoadingButton(ImagesConst.LineOffCopyCellBtn_upSkin, 350, 47, 70, 27, this);
            this._btn2.label = "" + Language.getString(71792);
            this._btn3 = UIFactory.gLoadingButton(ImagesConst.LineOffCopyCellBtn_upSkin, 350, 133, 70, 27, this);
            this._btn3.label = "" + Language.getString(71792);
            this._btn4 = UIFactory.gLoadingButton(ImagesConst.LineOffCopyCellBtn_upSkin, 350, 217, 70, 27, this);
            this._btn4.label = "" + Language.getString(71792);
            this._levelT6 = UIFactory.gImageBitmap(ImagesConst.openNewSerSevDayAct2Order6, 363, 7, this);
            this._levelT5 = UIFactory.gImageBitmap(ImagesConst.openNewSerSevDayAct2Order5, 363, 93, this);
            this._levelT4 = UIFactory.gImageBitmap(ImagesConst.openNewSerSevDayAct2Order4, 363, 176, this);
            this._level7Tip = UIFactory.gImageBitmap(ImagesConst.openNewSerSevDayAct2Order7Tip, 193, 83, this);
            this._level6 = UIFactory.gImageBitmap(ImagesConst.openNewSerSevDayAct2Title_8_6, 351, 7, this);
            this._level5 = UIFactory.gImageBitmap(ImagesConst.openNewSerSevDayAct2Title_8_5, 351, 92, this);
            this._level4 = UIFactory.gImageBitmap(ImagesConst.openNewSerSevDayAct2Title_8_4, 351, 176, this);
            this._btnArr = [];
            this._btnArr.push(this._btn1, this._btn2, this._btn3, this._btn4);
            this._btn1.configEventListener(MouseEvent.CLICK, this.onGet);
            this._btn2.configEventListener(MouseEvent.CLICK, this.onGet);
            this._btn3.configEventListener(MouseEvent.CLICK, this.onGet);
            this._btn4.configEventListener(MouseEvent.CLICK, this.onGet);
            Dispatcher.dispatchEvent(new DataEvent(EventName.RebateDayTargetInfoReq));
            this.updateBottomByDayNum2();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._btnArr = null;
            this._leftBg = null;
            this._rbg = null;
            this._fbg = null;
            this._level7 = null;
            this._firstTitle = null;
            this._tip4 = null;
            this._line1 = null;
            this._items1 = null;
            this._items2 = null;
            this._line2 = null;
            this._items3 = null;
            this._items4 = null;
            this._line3 = null;
            this._btn1 = null;
            this._btn2 = null;
            this._btn3 = null;
            this._btn4 = null;
            this._levelT6 = null;
            this._levelT5 = null;
            this._levelT4 = null;
            this._level7Tip = null;
            this._level6 = null;
            this._level5 = null;
            this._level4 = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function genItem() : RebateItem
        {
            var _loc_1:* = UIFactory.getUICompoment(RebateItem);
            return _loc_1;
        }// end function

        private function onGet(event:MouseEvent) : void
        {
            var _loc_2:* = event.target as GLoadingButton;
            var _loc_3:* = this._btnArr.indexOf(_loc_2);
            if (_loc_3 == -1)
            {
                return;
            }
            if (this._infoArr == null)
            {
                return;
            }
            var _loc_4:* = this._infoArr[_loc_3];
            Dispatcher.dispatchEvent(new DataEvent(EventName.RebateDayTargetGetReward, _loc_4));
            return;
        }// end function

        public function updateBottomByDayNum2() : void
        {
            this.updateRewards2();
            this.updateBtns();
            return;
        }// end function

        public function updateRewards2() : void
        {
            var _loc_5:Object = null;
            var _loc_1:* = RebateUtil.getDayTargetList();
            this._infoArr = [];
            if (_loc_1 == null)
            {
                return;
            }
            var _loc_2:int = 0;
            while (_loc_2 < _loc_1.length)
            {
                
                _loc_5 = _loc_1[_loc_2];
                if (this._numArr.indexOf(_loc_5.targetLevel) != -1)
                {
                    this._infoArr.push(_loc_5);
                }
                _loc_2++;
            }
            this._infoArr.sortOn("targetLevel", Array.DESCENDING | Array.NUMERIC);
            if (this._infoArr == null)
            {
                return;
            }
            var _loc_3:* = this._infoArr;
            var _loc_4:int = 0;
            while (_loc_4 < _loc_3.length && _loc_4 < 4)
            {
                
                this.updateOneGiftBag(_loc_3[_loc_4], _loc_4);
                _loc_4++;
            }
            this.updateTitles();
            return;
        }// end function

        private function updateTitles() : void
        {
            var _loc_3:GImageBitmap = null;
            var _loc_1:* = RebateUtil.getTargetType();
            var _loc_2:int = 4;
            while (_loc_2 <= 7)
            {
                
                _loc_3 = this["_level" + _loc_2] as GImageBitmap;
                if (_loc_3)
                {
                    _loc_3.imgUrl = "openNewSerSevDayAct2Title_" + this.targetTypeNameStrObj[_loc_1] + "_" + _loc_2 + ".swf";
                }
                _loc_2++;
            }
            return;
        }// end function

        private function updateOneGiftBag(param1:Object, param2:int) : void
        {
            var _loc_8:SPlayerItem = null;
            var _loc_9:RebateItem = null;
            var _loc_3:* = param1.giftBag;
            var _loc_4:* = ItemConfig.instance.getConfig(_loc_3);
            if (_loc_4 == null)
            {
                return;
            }
            var _loc_5:* = _loc_4.itemList;
            var _loc_6:* = QuestionCopyConfig.instance().getRewardItems(_loc_5);
            if (_loc_6 == null || _loc_6.length == 0)
            {
                return;
            }
            var _loc_7:* = this["_items" + (param2 + 1)] as CellsGridSprite;
            _loc_7.genCells(_loc_6.length);
            param2 = 0;
            while (param2 < _loc_6.length)
            {
                
                _loc_8 = _loc_6[param2];
                _loc_9 = _loc_7.cellArr[param2];
                _loc_9.updateInfo(_loc_8);
                param2++;
            }
            return;
        }// end function

        public function updateBtns() : void
        {
            var _loc_2:Object = null;
            var _loc_3:int = 0;
            var _loc_4:GLoadingButton = null;
            var _loc_5:int = 0;
            this.disableAllBtn();
            if (this._infoArr == null || Cache.instance.rebate.dayTargetLevelObj == null)
            {
                return;
            }
            var _loc_1:int = 0;
            while (_loc_1 < this._infoArr.length)
            {
                
                _loc_2 = this._infoArr[_loc_1];
                _loc_3 = _loc_2.targetLevel;
                _loc_4 = this._btnArr[_loc_1];
                _loc_5 = Cache.instance.rebate.dayTargetLevelObj[_loc_3];
                if (_loc_5 == 1)
                {
                    this.setGetBtn(_loc_4, true);
                }
                else if (_loc_5 == 2)
                {
                    this.setGetBtn(_loc_4, false);
                    _loc_4.label = "" + Language.getString(71793);
                }
                else
                {
                    this.setGetBtn(_loc_4, false);
                }
                _loc_1++;
            }
            return;
        }// end function

        private function disableAllBtn() : void
        {
            var _loc_2:GLoadingButton = null;
            var _loc_1:int = 0;
            while (_loc_1 < this._btnArr.length)
            {
                
                _loc_2 = this._btnArr[_loc_1];
                this.setGetBtn(_loc_2, false);
                _loc_1++;
            }
            return;
        }// end function

        private function setGetBtn(param1:GLoadingButton, param2:Boolean) : void
        {
            if (param2)
            {
                param1.enabled = true;
                param1.filters = null;
                EffectManager.glowFilterReg(param1);
            }
            else
            {
                EffectManager.glowFilterUnReg(param1);
                param1.enabled = false;
                param1.filters = [FilterConst.colorFilter2];
            }
            return;
        }// end function

    }
}
